package com.qkl.xiatang.app.web.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class AppWebConfig extends WebMvcConfigurationSupport {

    @Autowired
    private HandlerInterceptor appInterceptor;

    @Autowired
    private HandlerInterceptor appOpenApiInterceptor;

    @Value("${app.openApi}")
    private String openApi;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        String api = "/application/" + openApi;
        registry.addInterceptor(appInterceptor).addPathPatterns("/application/*","/application/*/*");
        registry.addInterceptor(appOpenApiInterceptor).addPathPatterns( api + "/*",api + "/*/*");
        super.addInterceptors(registry);
    }

    /**
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/application/*").addResourceLocations("");
        super.addResourceHandlers(registry);
    }
    **/
}
